﻿using MediatR;
using SY.BasicData.Api.Read.Applications.Basic.Command;
using SY.BasicData.Domain.Cultivation;
using SY.BasicData.ErrorCode;
using SY.BasicData.Infrastructures;

namespace SY.BasicData.Api.Read.Applications.Basic.CommandHandler
{
    public class CultivationCommpanyDeatilCommandHandler : IRequestHandler<CultivationCommpanyDeatilCommand, ApiResult<CultivationCommpanyModel>>
    {
        private readonly IBaseRepository<CultivationCommpanyModel> baseRepository;

        public CultivationCommpanyDeatilCommandHandler(IBaseRepository<CultivationCommpanyModel> baseRepository)
        {
            this.baseRepository = baseRepository;
        }

        public Task<ApiResult<CultivationCommpanyModel>> Handle(CultivationCommpanyDeatilCommand request, CancellationToken cancellationToken)
        {
            ApiResult<CultivationCommpanyModel> result = new ApiResult<CultivationCommpanyModel>();
            result.Code = ApiEnum.Success;
            result.Message = "养殖企业信息明细成功";
            var list=baseRepository.GetAll().Where(x=>x.Batch==request.Batch).FirstOrDefault();
            result.Data = list;
            return Task.FromResult(result);
        }
    }
}
